package main

import (
	"fmt"
	"io"
	"net"
	"os"
)

var (
	HOST  = "127.0.0.1"
	PORT  = "3333"
	PROTO = "tcp"
)

func main() {
	conn, err := net.Dial(PROTO, HOST+":"+PORT)
	defer conn.Close()

	if err != nil {
		fmt.Println("connect server error : ", err)
		return
	}
	ReadWrite(conn)
}

func ReadWrite(conn net.Conn) {
	message := "send message\n"
	_, err := conn.Write([]byte(message))
	if err != nil {
		fmt.Println("send message error : ", err)
		os.Exit(1)
	}
	conn.(*net.TCPConn).CloseWrite()

	buf, err := io.ReadAll(conn)
	if err != nil {
		fmt.Println("accept server message error : ", err)
		os.Exit(1)
	}
	fmt.Println("accept server message : ", string(buf))
}
